package PTA_JAVA.JavaA.Javademo22;

import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayIntegerStack arr = new ArrayIntegerStack(n);
        int m = sc.nextInt();
        for (int i = 0; i < m; i++) {
            System.out.println(arr.push(sc.nextInt()));
        }
        System.out.println(arr.peek()+","+arr.empty()+","+arr.size());
        System.out.println(arr.toString());
        int x = sc.nextInt();
        for (int i = 0; i < x; i++) {
            System.out.println(arr.pop());
        }
        System.out.println(arr.peek()+","+arr.empty()+","+arr.size());
        System.out.println(arr.toString());
    }
}
interface IntegerStack{
    public Integer push(Integer item);
//如果item为null，则不入栈直接返回null。如果栈满，也返回null。如果插入成功，返回item。

    public Integer pop();   //出栈，如果为空，则返回null。出栈时只移动栈顶指针，相应位置不置为null
    public Integer peek();  //获得栈顶元素，如果为空，则返回null.
    public boolean empty(); //如果为空返回true
    public int size();      //返回栈中元素个数

}
class ArrayIntegerStack implements IntegerStack{
    private Integer[] arr;
    private int top=0;

    public ArrayIntegerStack(int n) {
        arr = new Integer[n];
        Arrays.fill(arr,null);
    }

    @Override
    public Integer push(Integer item) {
        if(item.equals(null) || arr.length==top){
            return null;
        }
        arr[top++]=item;
        return item;
    }

    @Override
    public Integer pop() {
        if(top==0){
            return null;
        }
        return arr[--top];
    }

    @Override
    public Integer peek() {
        if(top==0){
            return null;
        }
        return arr[top-1];
    }

    @Override
    public boolean empty() {
        return top==0;
    }

    @Override
    public int size() {
        return top;
    }

    @Override
    public String toString() {
        return Arrays.toString(arr);
    }
}
